import Vue from 'vue'
import VueRouter from 'vue-router'
import login from "../views/login";
import main from "../views/main";
import student from "../components/student";
import cource from "../components/cource";
import cources from "../components/cources";
import account from "../components/account";
import rule from "../components/rule";
import user from "../components/user";
import classts from "../components/classts";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: login
  },
  {
    path:"/main",
    name:"main",
    component: main,
    children:[
      // {
      //   path:"/main/movie",
      //   name:"movieHome",
      //   component:movieHome
      // },
      {
        path:"/main/student",
        name:"student",
        component:student
      },
      {
        path:"/main/cource",
        name:"cource",
        component: cource
      },
      {
        path:"/main/account",
        name:"account",
        component: account
      },
      {
        path:"/main/cources",
        name:"cources",
        component: cources
      },
      {
        path:"/main/rule",
        name:"rule",
        component: rule
      },
      {
        path:"/main/user",
        name:"user",
        component: user
      },
      {
        path:"/main/classts",
        name:"classs",
        component: classts
      }
    ]
  }

]
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next) => {
  if(to.path == "/") {
    next();
  } else {
    let account = localStorage.getItem("account");
    if(account == undefined || account == null) {
      router.push("/");
    } else next();
  }
})

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
export default router
